package com.oschat.redis;

import com.oschat.entity.constants.Constants;
import com.oschat.entity.dto.SysSettingDto;
import com.oschat.entity.dto.TokenUserInfoDto;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @Description redis封装
 * @Classname RedisComponent
 * @Date 2024/11/2 13:33
 * @Created by panda
 */
@Component("redisComponent")
public class RedisComponent {
    @Resource
    private RedisUtils redisUtils;

    /*
    * 获取用户心跳
    * */
    public Long getUserHeartBeat(String userId){
        return (Long) redisUtils.get(Constants.REDIS_KEY_WS_USER_HEART_BEAT+userId);
    }

    public void saveTokenUserInfoDto(TokenUserInfoDto tokenUserInfoDto){
        redisUtils.setex(Constants.REDIS_KEY_WS_TOKEN+tokenUserInfoDto.getToken(),tokenUserInfoDto,Constants.REDIS_KEY_EXPIRES_DAY*Constants.REDIS_TIME_2);
        redisUtils.setex(Constants.REDIS_KEY_WS_TOKEN_USER+tokenUserInfoDto.getUserId()+tokenUserInfoDto.getToken(),tokenUserInfoDto.getToken(),Constants.REDIS_KEY_EXPIRES_DAY*Constants.REDIS_TIME_2);
    }

    public SysSettingDto getSysSetting(){
        SysSettingDto sysSettingDto = (SysSettingDto) redisUtils.get(Constants.REDIS_KEY_SYS_SETTING);
        sysSettingDto=sysSettingDto == null?new SysSettingDto():sysSettingDto;
        return sysSettingDto;
    }

    public void saveSysSetting(SysSettingDto sysSettingDto){
        redisUtils.set(Constants.REDIS_KEY_SYS_SETTING,sysSettingDto);
    }
}
